package com.woniuxy.common.utils;

import com.woniuxy.common.vo.TokenVo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class TokenUtil {
    public static TokenVo getTokenVo(){
        HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();

        String token = request.getHeader("token");
        JwtUtils jwtUtils = new JwtUtils();
        Integer id = (Integer) jwtUtils.parseToken(token, "id");
        String username = (String) jwtUtils.parseToken(token,"userName");
        String phone = (String) jwtUtils.parseToken(token,"phone");
        TokenVo tokenVo = new TokenVo(id,username,phone);
        return tokenVo;
    }
}
